package com.zhongshengnetwork.rightbe.keyboard.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.GridView;
import android.widget.RelativeLayout;

import com.zhongshengnetwork.rightbe.R;
import com.zhongshengnetwork.rightbe.common.CommonUtils;
import com.zhongshengnetwork.rightbe.dbmodel.PicdbModel;
import com.zhongshengnetwork.rightbe.keyboard.adapter.AppsAdapter;
import com.zhongshengnetwork.rightbe.keyboard.adapter.PicAdapter;
import com.zhongshengnetwork.rightbe.keyboard.data.AppBean;
import com.zhongshengnetwork.rightbe.keyboard.data.PicBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zhongsheng-luojianlan on 17/1/2.
 */

public class SimplePicGridView extends RelativeLayout {

    protected View view;

    public SimplePicGridView(Context context, PicdbModel picdbModel) {
        this(context, null, picdbModel);
    }

    public SimplePicGridView(Context context, AttributeSet attrs, PicdbModel picdbModel) {
        super(context, attrs);
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(R.layout.view_apps, this);
        init(picdbModel);
    }

    protected void init(PicdbModel picdbModel){
        GridView gv_apps = (GridView) view.findViewById(R.id.gv_apps);
        ArrayList<PicBean> mPicBeanList = new ArrayList<>();
        List<String> names = CommonUtils.stringToArrayList(picdbModel.getNames());
        for(int i = 0; i < names.size(); i++){
            PicBean picBean = new PicBean();
            picBean.setHost(picdbModel.getHost());
            picBean.setName(picdbModel.getName());
            picBean.setId((i+1)+"");
            picBean.setTitle(names.get(i));
            mPicBeanList.add(picBean);
        }
        PicAdapter adapter = new PicAdapter(getContext(),mPicBeanList);
        gv_apps.setAdapter(adapter);
    }
}
